putil-defineconst
Helper function for defining & configuring consts and properties easily
Installation
$ npm install putil-defineconst --save
Usage
defineConst([target], name, value, [enumerable=true])
- targe [
Object
] Target object - name [
String
] Property name - value [
*
] Property value - enumerable ['Boolean'] Enumerable flag
const defineConst = require('putil-defineconst');
const a = {};
defineConst(a, 'prm1', 123);
a.prm1 = 1234;
assert.equal(a.prm1, 123);
assert.equal(a.propertyIsEnumerable('prm1'), true);
defineConst([target], name, value, [config])
- targe [
Object
] Target object - name [
String
] Property name - value [
*
] Property value - config ['Object'] Configuration object
const defineConst = require('putil-defineconst');
const a = {};
defineConst(a, 'prm1', 123, {writable: false, enumerable: false});
a.prm1 = 1234;
assert.equal(a.prm1, 123);
assert.equal(a.propertyIsEnumerable('prm1'), false);
defineConst([target], properties, [enumerable=true])
- targe [
Object
] Target object - name [
Object
] Key/value pair object that includes properties to be defined - enumerable ['Boolean'] Enumerable flag
const a = {};
defineConst(a, {
prm1: 123,
prm2: 'abc'
});
a.prm1 = 1234;
a.prm2 = 'aaa';
assert.equal(a.prm1, 123);
assert.equal(a.propertyIsEnumerable('prm1'), true);
assert.equal(a.prm2, 'abc');
assert.equal(a.propertyIsEnumerable('prm2'), true);
defineConst([target], properties, [config])
- targe [
Object
] Target object - name [
Object
] Key/value pair object that includes properties to be defined - config ['Object'] Configuration object
const a = {};
defineConst(a, {
prm1: 123,
prm2: 'abc'
}, {
writable: false,
enumerable: true
});
a.prm1 = 1234;
a.prm2 = 'aaa';
assert.equal(a.prm1, 123);
assert.equal(a.propertyIsEnumerable('prm1'), true);
assert.equal(a.prm2, 'abc');
assert.equal(a.propertyIsEnumerable('prm2'), true);
Node Compatibility
License
MIT